home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Online / opennap / part_channel.c < prev    next >
C/C++ Source or Header  |  2001-06-08  |  2KB  |  88 lines

  1. /* Copyright (C) 2000-1 drscholl@users. sourceforge.net
  2.    This is free software distributed under the terms of the
  3.    GNU Public License.  See the file COPYING for details.
  4.  
  5.    $Id: part_channel.c,v 1.20 2001/02/15 08:39:45 drscholl Exp $ */
  6.  
  7. #ifndef WIN32
  8. #include <unistd.h>
  9. #endif
  10. #include <string.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include "opennap.h"
  14. #include "debug.h"
  15.  
  16. /* remove this user from the channel list */
  17. static LIST *
  18. channel_remove (CHANNEL * chan, USER * user)
  19. {
  20.     LIST **list, *tmpList;
  21.     CHANUSER *chanUser;
  22.  
  23.     for (list = &chan->users; *list; list = &(*list)->next)
  24.     {
  25.     chanUser = (*list)->data;
  26.     ASSERT (chanUser->magic == MAGIC_CHANUSER);
  27.     if (chanUser->user == user)
  28.     {
  29.         tmpList = *list;
  30.         *list = (*list)->next;
  31.         FREE (tmpList);
  32.         FREE (chanUser);
  33.         break;
  34.     }
  35.     }
  36.     return chan->users;
  37. }
  38.  
  39. /* remove `user' from channel `chan' */
  40. /* this function only removes the user entry from the channel list and
  41.    notifies any local users of the departure.  the server-server message
  42.    happens in the caller of this routine since in the QUIT case we don't
  43.    send PART messages across servers when a client quits */
  44. void
  45. part_channel (CHANNEL * chan, USER * user)
  46. {
  47.     int len;
  48.     CHANUSER *chanUser;
  49.     LIST *list;
  50.  
  51.     ASSERT (validate_channel (chan));
  52.     ASSERT (validate_user (user));
  53.  
  54.     /* clear the invite list */
  55.     if (chan->invited)
  56.     chan->invited = list_delete (chan->invited, user);
  57.  
  58.     chan->users = channel_remove (chan, user);
  59.     if (chan->users)
  60.     {
  61.     if ((chan->flags & ON_CHANNEL_QUIET) == 0)
  62.     {
  63.         /* notify other members of this channel that this user has parted */
  64.         len = form_message (Buf, sizeof (Buf), MSG_SERVER_PART,
  65.             "%s %s %d %d", chan->name, user->nick,
  66.             user->shared, user->speed);
  67.         for (list = chan->users; list; list = list->next)
  68.         {
  69.         /* we only notify local clients */
  70.         chanUser = list->data;
  71.         ASSERT (chanUser->magic == MAGIC_CHANUSER);
  72.         if (ISUSER (chanUser->user->con))
  73.         {
  74.             if (!user->cloaked
  75.                 || chanUser->user->level >= LEVEL_MODERATOR)
  76.             queue_data (chanUser->user->con, Buf, len);
  77.         }
  78.         }
  79.     }
  80.     }
  81.     /* if there are no users left in this channel, destroy it */
  82.     else if ((chan->flags & ON_CHANNEL_REGISTERED) == 0)
  83.     {
  84.     log ("part_channel: destroying channel %s", chan->name);
  85.     hash_remove (Channels, chan->name);
  86.     }
  87. }
  88.